





//
//  NSString+CaculateLenght.m
//  房源、商铺、写字楼详情页
//
//  Created by MB__Lee on 2018/5/22.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "NSString+CaculateLenght.h"

#define MarginTwice 

@implementation NSString (CaculateLenght)



-(CGFloat)widthForStringFontSize:(UIFont *)font{
    
    NSDictionary *dic = @{NSFontAttributeName:font};
    CGSize size = [self sizeWithAttributes:dic];
    return size.width;
}
-(CGFloat)heightForStringFontSize:(UIFont *)font width:(CGFloat)width{
    NSDictionary *dic = @{NSFontAttributeName:font};
    CGSize size = [self boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return  size.height;
        
}
-(CGFloat)heightForStringFontSize:(UIFont *)font width:(CGFloat)width dict:(NSDictionary *)dict{
    if (dict == nil) {
        return  [self heightForStringFontSize:font width:width];
    }
    
    NSMutableDictionary *mutDic = [NSMutableDictionary dictionary];
    mutDic[NSFontAttributeName] = font;
    
    [mutDic addEntriesFromDictionary:dict];
    
    CGSize size  = [self boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    return  size.height;
    
}



@end
